package com.ouwen.smartpay.service.chain.slots.check;

import com.fm.common.emuns.ResponseCode;
import com.fm.core.common.exception.OrderCheckException;
import com.fm.core.common.facade.BizResultBase;
import com.fm.core.common.facade.MerchOrderBase;
import com.ouwen.smartpay.openapi.order.ServiceOrder;
import com.ouwen.smartpay.service.chain.context.Context;
import com.ouwen.smartpay.service.chain.slotchain.AbstractLinkedProcessorSlot;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author <a href="http://youngitman.tech">青年IT男</a>
 * @version v1.0.0
 * @className BizOrderCheckSlot
 * @description 业务订单校验
 * @JunitTest: {@link  }
 * @date 2020-04-28 15:07
 **/
public class BizOrderCheckSlot extends AbstractLinkedProcessorSlot<ServiceOrder> {

    Logger logger = LoggerFactory.getLogger(getClass());

    @Override
    public void entry(Context context, ServiceOrder order, Object... args) throws Throwable {

        try {

            MerchOrderBase bizOrder = context.getOrder();

            //业务订单校验
            bizOrder.check();

            fireEntry(context, order, args);

        } catch (OrderCheckException e) {

            logger.info("业务订单校验异常:", e);

            BizResultBase result = new BizResultBase();

            result.setRespCode(ResponseCode.FAIL.code());

            result.setRespMsg(ResponseCode.FAIL.message());

            result.setDescription(e.getMessage());

            exit(context, order, args,result);

        }
    }

    @Override
    public void exit(Context context, Object... args) {

        fireExit(context, args);

    }
}
